<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document)
            .ready(
            function () {
                $(
                        'input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea',
                        '.form').iTextClear();
            });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" type="text/css" href="${ctx}/css/flexigrid.css">

<link rel="stylesheet" media="screen" href="CSS/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript"
        src="lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<link href="${ctx}/css/black-tie/jquery-ui-1.7.3.custom.css"
      rel="stylesheet" type="text/css"/>
<!-- DATATABLES CSS END -->
<h1 class="page-title">新员工面试安排 - ${title}</h1>

<div class="container_12 clearfix leading">
    <div class="side grid_12 leading">
        <form class="form has-validation" id="post_form">
            <s:if
                    test="#request.interviewArrangeId != null && #request.interviewArrangeId > 0">
                <input id="hid_iarId" type="hidden" value="${interviewArrangeId}"/>
            </s:if>
            <s:else>
                <input id="hid_iarId" type="hidden" value="-1"/>
            </s:else>
            <div class="clear"></div>
            <div class="clearfix">
                <label class="form-label">面试职位</label>

                <div class="form-input">
                    <select id="duty_sel">
                        <s:iterator value="#request.inviteArranges" var="invitearrange"
                                    status="st">
                            <s:if
                                    test="(#st.index == 0 && #request.interviewArrange == null) || (#request.interviewArrange != null && #request.interviewArrange.grade.id = #invitearrange.inviteApply.grade.id)">
                                <option value="${invitearrange.inviteApply.grade.id}"
                                        selected="selected">${invitearrange.inviteApply.organization.path}/${invitearrange.inviteApply.grade.duty.dutyName}</option>
                            </s:if>
                            <s:else>
                                <option value="${invitearrange.inviteApply.grade.id}">${invitearrange.inviteApply.grade.duty.dutyName}</option>
                            </s:else>
                        </s:iterator>
                    </select>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix">
                <label class="form-label">从离职员工或人才库中选择</label>

                <div class="form-input">
                    <input id="iput_empIds" type="hidden" value=""/> <span
                        id="sel_emp_span"
                        style="display: inline-block; vertical-align: bottom; border-bottom: solid 1px #ccc; width: 150px; overflow: hidden; text-overflow: ellipsis;"></span>
                    <a class="button" style="margin-top: 10px"
                       href="javascript:void(0)" onclick="selectEmployee()"><span
                            style="background: url(${ctx}/images/img/zoom.png)" class="icon">&nbsp;</span>选择</a>

                    <a class="button" style="margin-top: 10px"
                       href="#employee/talent_add.xhtml"><span
                            style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加</a>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="form-action clearfix">
                <button class="button" type="button" onclick="checkForm()">添加</button>
                <button class="button" type="reset">重置</button>
                <a class="button" href="javascript:void(0)" onclick="history.back()"><span
                        style="background: url(${ctx}/images/img/arrow_undo.png)"
                        class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>
<div class="clear"></div>

<!-- 员工选择层 -->
<div id="employee_dialog" title="选择面试人员">
    <div class="clearfix">
        <table id="employee_table" style="display: none;"></table>
        <div class="clearfix"></div>
    </div>
</div>

<script type="text/javascript">
    var grid = $("#employee_table").flexigrid({
        //width : 640,
        //height : 260,
        url:'${ctx}/ajax/query_noffemployee.xhtml',
        dataType:'json',
        colModel:[
            {
                display:'编号',
                name:'EmployeeinfoBase.id',
                width:25,
                sortable:true,
                align:'center',
                hide:false
            },
            {
                display:'姓名',
                name:'name',
                width:50,
                sortable:false,
                align:'center'
            },
            {
                display:'性别',
                name:'sex',
                width:20,
                sortable:true,
                align:'center'
            },
            {
                display:'出生日期',
                name:'birthday',
                width:60,
                sortable:true,
                align:'right',
            },
            {
                display:'薪资',
                name:'compensation',
                width:50,
                sortable:true,
                align:'right',
            },
            {
                display:'学历',
                name:'certificate',
                width:120,
                sortable:true,
                align:'center'
            },
            {
                display:'最高毕业学校',
                name:'school',
                width:200,
                sortable:true,
                align:'center'
            }
        ],
        errormsg:'发生异常',
        sortname:"id",
        sortorder:"desc",
        usepager:true,
        //title : '信息发布管理',
        pagestat:'显示记录从{from}到{to}，总数 {total} 条',
        useRp:true,
        rp:10,
        //rpOptions : [ 10, 15, 20, 30, 40, 100 ], //可选择设定的每页结果数
        rpOptions:[ 10 ], //可选择设定的每页结果数
        nomsg:'没有符合条件的记录存在',
        minColToggle:1, //允许显示的最小列数
        showTableToggleBtn:true,
        autoload:true, //自动加载，即第一次发起ajax请求
        resizable:false, //table是否可伸缩
        procmsg:'加载中, 请稍等 ...',
        hideOnSubmit:true, //是否在回调时显示遮盖
        blockOpacity:0.5, //透明度设置
        rowbinddata:true,
        checkbox:true
    });

    $("#employee_dialog")
            .dialog(
            {
                autoOpen:false,
                height:360,
                width:650,
                modal:true,
                overlay:{
                    backgroundColor:'#000',
                    opacity:0.5
                },
                buttons:{
                    '确定':function () {
                        var ids = "";
                        var names = "";
                        for (var i = 0; i < $('.trSelected', grid).length; i++) {
                            ids += ","
                                    + $('.trSelected', grid).find(
                                    "td:first").eq(i).text();//获取id
                            names += ","
                                    + $('.trSelected', grid).find(
                                    "td:nth-child(3)").eq(i)
                                    .text();//获取name
                        }
                        $("#iput_empIds").val(ids.substring(1));
                        $("#sel_emp_span").html(names.substring(1));
                        $(this).dialog('close');
                    },
                    '取消':function () {
                        $(this).dialog('close');
                    }
                }
            });

    function selectEmployee() {
        $("#employee_dialog").dialog("open");
    }

    /**
     * 提交数据
     */
    function checkForm() {
        if ($("#iput_empIds").val().trim() == "") {
            alert("请选择需要面试的人员!");
            return;
        }

        var url = "${ctx}/invite/post_interviewarrange.xhtml";
        $.ajax(
                url,
                {
                    type:"POST",
                    data:{
                        "interviewArrangeId":$("#hid_iarId").val(),
                        "interviewEmployeeIds":$("#iput_empIds")
                                .val(),
                        "gradeId":$("#duty_sel").val()
                    },
                    dataType:"html",
                    cache:false,
                    success:function (a) {
                        alert("添加面试安排成功！");
                        location.href = "${ctx}/index.xhtml#invite/invite_list.xhtml?p=interview_arrange";
                    },
                    error:function (XMLHttpRequest, textStatus, errorThrown) {
                        alert('提交申请发生异常');
                    },
                    complete:function () {
                    }
                });
    }
</script>
